<?php

$eop=(substr(dirname($_SERVER["SCRIPT_NAME"]),-1,1)=="/") ? '' : '/';

define('ROOT_DIR', dirname(dirname(__FILE__)));
define('APPLICATION_PATH', ROOT_DIR . '/application');
define('COMPONENTS_ADMIN_PATH', APPLICATION_PATH.'/resources/admin/components');
define('BASE_URL', 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER["SCRIPT_NAME"]).$eop);
/**
 * @todo
 * esto debe reemplazarse por un admin se usuarios, sesiones y perfiles
 */
define('ADMIN_USERNAME', 'admin');
define('ADMIN_PASSWORD', 'admin');

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    get_include_path(),
)));

           
require_once 'Zend/Loader/Autoloader.php';

$loader = Zend_Loader_Autoloader::getInstance();
set_include_path('.'
        . PATH_SEPARATOR . ROOT_DIR.'/library'
        . PATH_SEPARATOR . APPLICATION_PATH . '/models'
        . PATH_SEPARATOR . APPLICATION_PATH . '/forms'
        . PATH_SEPARATOR . get_include_path()
);
//$loader->registerNamespace('Zwei_');
$loader->setFallbackAutoloader(true);

Zend_Session::start();  

// Inicializar el MVC
Zend_Layout::startMvc(array('layoutPath' => ROOT_DIR.'/application/views/layouts'));

// Run!
$frontController = Zend_Controller_Front::getInstance();
$frontController->addControllerDirectory(ROOT_DIR.'/application/controllers');
$frontController->throwExceptions(true);

$config = new Zend_Config_Ini(ROOT_DIR.'/application/configs/application.ini', 'production');
$db = Zend_Db::factory($config->db);
//$db->getProfiler()->setEnabled(true);//para debug
Zend_Db_Table::setDefaultAdapter($db);

//$frontController->setBaseUrl(BASE_URL);

try {
    $frontController->dispatch();
} catch(Exception $e) {
	Zwei_Utils_Debug::write(nl2br($e->__toString()));
	//echo nl2br($e->__toString());
}
            
            